package com.lin.controller;

import com.lin.annotation.MyLog;
import com.lin.pojo.PriceChange;
import com.lin.services.PriceChangeService;
import com.lin.utils.PageUnit;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * ClassName PriceChangeController
 * Package com.lin.controller
 *
 * @author hellcat
 * Date 2020/3/23
 * Description:
 * 🐾
 */
@Controller
@RequestMapping("/priceChange")
public class PriceChangeController {


    @Autowired
    private PriceChangeService priceChangeService;

    @MyLog("查询进价变动")
    @RequiresPermissions("wares:priceChange:list")
    @RequestMapping(value = "/toPriceChange", method = RequestMethod.GET)
    public String toPriceChange(HttpServletRequest request) {
        request.setAttribute("ddId", "PriceChange");
        return "priceChangeMain";
    }

    @RequiresPermissions("wares:priceChange:list")
    @RequestMapping(value = "/priceLog", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> getPriceChange(HttpServletRequest request) {
        String date = request.getParameter("searchDate");
        String waresId = request.getParameter("searchWaresId");
        int page = Integer.parseInt(request.getParameter("page"));
        int limit = Integer.parseInt(request.getParameter("limit"));
        List<PriceChange> list = priceChangeService.getPriceChange(waresId, date);
        return PageUnit.Page(list, page, limit);
    }

    @MyLog("修改商品售价")
    @RequiresPermissions("wares:wares:update")
    @RequestMapping(value = "/updateWaresPrice", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> updateWaresPrice(HttpServletRequest request) {
        String id = request.getParameter("id");
        String price = request.getParameter("price");
        return priceChangeService.updateWaresPrice(id, price);
    }
}
